/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* Merge(ListNode* pHead1, ListNode* pHead2)
    {
        ListNode* phead = new ListNode(0);
        ListNode* list_new = phead;
        while(pHead1 || pHead2){
            if(pHead1==NULL){
                list_new->next=pHead2;
                break;
            }
            else if(pHead2==NULL){
                list_new->next = pHead1;
                break;
            }
           if((pHead1->val)>(pHead2->val))
           {
                list_new->next = pHead2;
                list_new = list_new->next;
                pHead2=pHead2->next;
           }
           else{
                list_new->next = pHead1;
                list_new = list_new->next;
                pHead1=pHead1->next;
           }
        }
        return phead->next;
    }
};
